package com.gmail.dmitryustimov.ms.java7.visitor.mod_reflective.example.example1;


public class Demo {
    public static void main(String[] args) {
//        //calculate the expression x = 2*y+3
//        Expression expr =
//                new Assignment( new Variable("x"),
//                        new AddExpr( new MulExpr( new Constant(2),
//                                new Variable("y") ),
//                                new Constant(3) ) );

        //calculate the expression x = 2*9+3
        Expression expr =
                new Assignment(
                        new Variable("x"),
                        new AddExpr(
                                new MulExpr(new Constant(2), new Constant(9)),
                                new Constant(3)
                        )
                );

        ExtendCalculationVisitor calculator =
                new ExtendCalculationVisitor();
        try {
            calculator.visit(expr);
            System.out.println( "result: " + calculator.getResult() );
        }
        catch ( NoSuchMethodException e ) { /* code handling */ }
    }
}
